package logic

import (
	"context"
	"house_srv/mysql"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseListLogic {
	return &HouseListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseListLogic) HouseList(in *house.HouseListRequest) (*house.HouseListResponse, error) {
	// todo: add your logic here and delete this line
	houses := mysql.House{}
	list, err := houses.HouseList(int(in.StarPrice), int(in.EndPrice))
	if err != nil {
		logx.Info("列表信息错误", err)
		return nil, err
	}
	var slice []*house.HouseList
	for _, h := range list {
		houseList := house.HouseList{
			UserId:    h.UserId,
			HouseName: h.HouseName,
			Price:     h.Price,
			Floor:     h.Floor,
			Area:      h.Area,
			Cover:     h.Cover,
			Address:   h.Address,
			Describe:  h.Describe,
			HouseId:   int64(h.ID),
		}
		slice = append(slice, &houseList)
	}
	return &house.HouseListResponse{
		List: slice,
	}, nil
}
